<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta content="text/javascript" http-equiv="content-script-type">
<title>tango.core.Atomic</title>

<link rel="stylesheet" type="text/css" href="css/style.css">
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="css/ie56hack.css"><![endif]-->
<script language="JavaScript" src="js/util.js" type="text/javascript"></script>
<script language="JavaScript" src="js/tree.js" type="text/javascript"></script>
<script language="JavaScript" src="js/explorer.js" type="text/javascript"></script>
<script>
function anchorFromTitle(title, path, ext) {
  var url = path + title + "." + ext;
  document.write("<a href='" + url + "'>" + title + "</a>");
  }
</script>
</head><body>
<div id="tabarea"></div><div id="explorerclient"></div>
<div id="content"><script>explorer.initialize("tango.core.Atomic");</script>
        <table class="content">
                <tr><td id="docbody"><h1><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327">tango.core.Atomic</a></h1>
                
<font color="black">The atomic module is intended to provide some basic support for lock-free
 concurrent programming.  Some common operations are defined, each of which
 may be performed using the specified memory barrier or a less granular
 barrier if the hardware does not support the version requested.  This
 model is based on a design by Alexander Terekhov as outlined in
 <a href=http://groups.google.com/groups?threadm=3E4820EE.6F408B25%40web.de>
 this thread</a>.  Another useful reference for memory ordering on modern
 architectures is <a href=http://www.linuxjournal.com/article/8211>this
 article by Paul McKenney</a>.</font><br><br>
<b>License:</b><br>
BSD style: see <a href="http://www.dsource.org/projects/tango/wiki/LibraryLicense">license.txt</a><br><br>
<b>Authors:</b><br>
Sean Kelly<br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>enum <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L28">msync</a></span>
<script>explorer.outline.addDecl('msync');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Memory synchronization flag.  If the supplied option is not available on the
 current platform then a stronger method will be used instead.
 </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L30">raw</a></span>
<script>explorer.outline.addDecl('raw');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">not sequenced</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L31">hlb</a></span>
<script>explorer.outline.addDecl('hlb');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">hoist-load barrier</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L32">hsb</a></span>
<script>explorer.outline.addDecl('hsb');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">hoist-store barrier</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L33">slb</a></span>
<script>explorer.outline.addDecl('slb');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">sink-load barrier</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L34">ssb</a></span>
<script>explorer.outline.addDecl('ssb');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">sink-store barrier</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L35">acq</a></span>
<script>explorer.outline.addDecl('acq');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">hoist-load + hoist-store barrier</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L36">rel</a></span>
<script>explorer.outline.addDecl('rel');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">sink-load + sink-store barrier</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L37">seq</a></span>
<script>explorer.outline.addDecl('seq');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">fully sequenced &#40;acq + rel&#41;</font><br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L108">atomicLoad</a></span>
<script>explorer.outline.addDecl('atomicLoad');</script>( msync ms, T );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Supported msync values:
  msync.raw
  msync.hlb
  msync.acq
  msync.seq
     </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>T <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L120">atomicLoad</a></span>
<script>explorer.outline.addDecl('atomicLoad');</script>(inout T <span class="funcparam">val</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Refreshes the contents of 'val' from main memory.  This operation is
 both lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">val</span></td><td>The value to load.  This value must be properly aligned.</td></tr></table><br>
<b>Returns:</b><br>
The loaded value.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L140">atomicStore</a></span>
<script>explorer.outline.addDecl('atomicStore');</script>( msync ms, T );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Supported msync values:
  msync.raw
  msync.ssb
  msync.acq
  msync.rel
  msync.seq
     </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>void <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L150">atomicStore</a></span>
<script>explorer.outline.addDecl('atomicStore');</script>(inout T <span class="funcparam">val</span>, T <span class="funcparam">newval</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Stores 'newval' to the memory referenced by 'val'.  This operation
 is both lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">val</span></td><td>The destination variable.</td></tr>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">newval</span></td><td>The value to store.</td></tr></table><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L170">atomicStoreIf</a></span>
<script>explorer.outline.addDecl('atomicStoreIf');</script>( msync ms, T );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Supported msync values:
  msync.raw
  msync.ssb
  msync.acq
  msync.rel
  msync.seq
     </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>bool <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L184">atomicStoreIf</a></span>
<script>explorer.outline.addDecl('atomicStoreIf');</script>(inout T <span class="funcparam">val</span>, T <span class="funcparam">newval</span>, T <span class="funcparam">equalTo</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Stores 'newval' to the memory referenced by 'val' if val is equal to
 'equalTo'.  This operation is both lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">val</span></td><td>The destination variable.</td></tr>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">newval</span></td><td>The value to store.</td></tr>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">equalTo</span></td><td>The comparison value.</td></tr></table><br>
<b>Returns:</b><br>
true if the store occurred, false if not.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L204">atomicIncrement</a></span>
<script>explorer.outline.addDecl('atomicIncrement');</script>( msync ms, T );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Supported msync values:
  msync.raw
  msync.ssb
  msync.acq
  msync.rel
  msync.seq
     </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>T <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L224">atomicIncrement</a></span>
<script>explorer.outline.addDecl('atomicIncrement');</script>(inout T <span class="funcparam">val</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">This operation is only legal for built-in value and pointer types,
 and is equivalent to an atomic "val = val + 1" operation.  This
 function exists to facilitate use of the optimized increment
 instructions provided by some architecures.  If no such instruction
 exists on the target platform then the behavior will perform the
 operation using more traditional means.  This operation is both
 lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">val</span></td><td>The value to increment.</td></tr></table><br>
<b>Returns:</b><br>
The result of an atomicLoad of val immediately following the
  increment operation.  This value is not required to be equal to the
  newly stored value.  Thus, competing writes are allowed to occur
  between the increment and successive load operation.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L244">atomicDecrement</a></span>
<script>explorer.outline.addDecl('atomicDecrement');</script>( msync ms, T );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Supported msync values:
  msync.raw
  msync.ssb
  msync.acq
  msync.rel
  msync.seq
     </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>T <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L264">atomicDecrement</a></span>
<script>explorer.outline.addDecl('atomicDecrement');</script>(inout T <span class="funcparam">val</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">This operation is only legal for built-in value and pointer types,
 and is equivalent to an atomic "val = val - 1" operation.  This
 function exists to facilitate use of the optimized decrement
 instructions provided by some architecures.  If no such instruction
 exists on the target platform then the behavior will perform the
 operation using more traditional means.  This operation is both
 lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">val</span></td><td>The value to decrement.</td></tr></table><br>
<b>Returns:</b><br>
The result of an atomicLoad of val immediately following the
  increment operation.  This value is not required to be equal to the
  newly stored value.  Thus, competing writes are allowed to occur
  between the increment and successive load operation.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>struct <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1304">Atomic</a></span>
<script>explorer.outline.addDecl('Atomic');</script>( T );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">This struct represents a value which will be subject to competing access.
 All accesses to this value will be synchronized with main memory, and
 various memory barriers may be employed for instruction ordering.  Any
 primitive type of size equal to or smaller than the memory bus size is
 allowed, so 32-bit machines may use values with size &lt;= int.sizeof and
 64-bit machines may use values with size &lt;= long.sizeof.  The one exception
 to this rule is that architectures that support DCAS will allow double-wide
 storeIf operations.  The 32-bit x86 architecture, for example, supports
 64-bit storeIf operations.
 </font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1311">load</a></span>
<script>explorer.outline.addDecl('load');</script>( msync ms = msync.seq );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>T <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1324">load</a></span>
<script>explorer.outline.addDecl('load');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Refreshes the contents of this value from main memory.  This
 operation is both lock-free and atomic.</font><br><br>
<b>Returns:</b><br>
The loaded value.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1336">store</a></span>
<script>explorer.outline.addDecl('store');</script>( msync ms = msync.seq );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>void <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1350">store</a></span>
<script>explorer.outline.addDecl('store');</script>(T <span class="funcparam">newval</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Stores 'newval' to the memory referenced by this value.  This
 operation is both lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">newval</span></td><td>The value to store.</td></tr></table><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1362">storeIf</a></span>
<script>explorer.outline.addDecl('storeIf');</script>( msync ms = msync.seq );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>bool <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1380">storeIf</a></span>
<script>explorer.outline.addDecl('storeIf');</script>(T <span class="funcparam">newval</span>, T <span class="funcparam">equalTo</span>);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Stores 'newval' to the memory referenced by this value if val is
 equal to 'equalTo'.  This operation is both lock-free and atomic.</font><br><br>
<b>Params:</b><br>
<table>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">newval</span></td><td>The value to store.</td></tr>
<tr><td nowrap valign="top" style="padding-right: 8px"><span class="funcparam">equalTo</span></td><td>The comparison value.</td></tr></table><br>
<b>Returns:</b><br>
true if the store occurred, false if not.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1402">increment</a></span>
<script>explorer.outline.addDecl('increment');</script>( msync ms = msync.seq );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>T <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1424">increment</a></span>
<script>explorer.outline.addDecl('increment');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">This operation is only legal for built-in value and pointer
 types, and is equivalent to an atomic "val = val + 1" operation.
 This function exists to facilitate use of the optimized
 increment instructions provided by some architecures.  If no
 such instruction exists on the target platform then the
 behavior will perform the operation using more traditional
 means.  This operation is both lock-free and atomic.</font><br><br>
<b>Returns:</b><br>
The result of an atomicLoad of val immediately following the
  increment operation.  This value is not required to be equal to
  the newly stored value.  Thus, competing writes are allowed to
  occur between the increment and successive load operation.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>template <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1436">decrement</a></span>
<script>explorer.outline.addDecl('decrement');</script>( msync ms = msync.seq );</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<script>explorer.outline.incSymbolLevel();</script>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>T <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/core/Atomic.d?rev=3327#L1458">decrement</a></span>
<script>explorer.outline.addDecl('decrement');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">This operation is only legal for built-in value and pointer
 types, and is equivalent to an atomic "val = val - 1" operation.
 This function exists to facilitate use of the optimized
 decrement instructions provided by some architecures.  If no
 such instruction exists on the target platform then the behavior
 will perform the operation using more traditional means.  This
 operation is both lock-free and atomic.</font><br><br>
<b>Returns:</b><br>
The result of an atomicLoad of val immediately following the
  increment operation.  This value is not required to be equal to
  the newly stored value.  Thus, competing writes are allowed to
  occur between the increment and successive load operation.<br><br></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></dd></dl>
<script>explorer.outline.decSymbolLevel();</script></td></tr>
                <tr><td id="docfooter">
                        Copyright (C) 2005-2006 Sean Kelly.  All rights reserved. :: page rendered by CandyDoc. Generated by <a href="http://code.google.com/p/dil">dil</a> on Tue Mar  4 22:45:34 2008.
                </td></tr>
        </table>
</div>
<script></script>
</body></html>